<template>
  <div>
    <!-- 最近更新管理 -->
    <!-- 按钮上面的导航 -->
    <!-- <el-row style="margin: 18px 0px 0px 18px "> -->
    <el-row>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/admin/dashboard' }">管理中心</el-breadcrumb-item>
        <el-breadcrumb-item>系统管理</el-breadcrumb-item>
        <el-breadcrumb-item>日志管理</el-breadcrumb-item>
      </el-breadcrumb>
    </el-row>

    <!-- 搜索与添加按钮 -->
    <div style="margin-top: 15px; margin-left: 12px;">
      <el-button style="float:left;" type="primary" icon="el-icon-refresh" @click="loadLogs()" >刷新</el-button>
    </div>

    <el-card style="margin-top: 15px;margin: 15px 1%;width: 98%">
      <el-table :data="fromData" border style="width: 100%" :max-height="tableHeight">
        <el-table-column prop="id" width="55" label="id"></el-table-column>
        <el-table-column prop="classesName" label="执行类名" fit></el-table-column>

        <el-table-column prop="ip" width="115" label="ip地址"></el-table-column>
        <el-table-column prop="methodsName" width="130" label="方法名称"></el-table-column>
        <el-table-column prop="paramses" width="145" label="请求的参数"></el-table-column>
        <el-table-column prop="remark" width="160" label="备注"></el-table-column>
        <el-table-column prop="userName" width="100" label="用户名" fit></el-table-column>
        <el-table-column prop="createTime" width="155" label="创建时间"></el-table-column>
      </el-table>
      <div style="margin: 20px 0 50px 0">
        <el-pagination
          background
          style="float:right;"
          layout="total, prev, pager, next, jumper"
          @current-change="handleCurrentChange"
          :page-size="pageSize"
          :total="total"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'log',
  data () {
    return {
      fromData: [],
      pageSize: 10,
      total: 0
    }
  },
  mounted () {
    this.loadLogs()
  },
  computed: {
    tableHeight () {
      // table  card的高度
      return window.innerHeight - 300
    }
  },
  methods: {
    loadLogs () {
      var _this = this
      this.$axios.post('/admin/sysLog/' + this.pageSize + '/1').then((resp) => {
        if (resp && resp.data.code === 200) {
          _this.fromData = resp.data.result.content
          _this.total = resp.data.result.totalElements
           this.$message({
              type: 'success',
              message: '刷新成功'
            })
        } else {
          // 从后端返回错误信息
            this.$alert('<p style=" color:#F00;">' + resp.data.message + '</p>', '错误提示', {
              dangerouslyUseHTMLString: true
            })
        }
      })
    },
    handleCurrentChange (page) {
      var _this = this
      this.$axios.post('/admin/sysLog/' + this.pageSize + '/' + page + '/').then((resp) => {
        if (resp && resp.data.code === 200) {
          _this.fromData = resp.data.result.content
          _this.total = resp.data.result.totalElements
        } else {
              // 从后端返回错误信息
              this.$alert(resp.data.message, '错误提示', {
              type: 'error',
              dangerouslyUseHTMLString: true
              })
        }
      })
    }

  }
}
</script>

<style scoped>
.add-link {
  margin: 18px 0 15px 10px;
  float: left;
}
</style>
